package com.example.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 2. @Description 阿里云短信发送
 * 3. @Author wj
 * 5. @Version 1.0
 */

public class AliyunSmsUtil {
    private final static Logger logger = LoggerFactory.getLogger(AliyunSmsUtil.class);

    /**
     * @Description
     * @Author wj
     * @param type :数字类型 场景
     * @param params:: 参数
     * @Version 1.0
     */

    public static void aliyunSendSms(Map<String, String> params, Integer type) {
        try {
            String tem = "";//短信模板号
            String templateParam = "";//短信模板内容
            switch (type) {
                case 1:     //忘记密码、用户中心修改手机号时发送短信验证码、电子卡绑定时发送验证码
                    tem = "SMS_461880566";
                    String code = String.valueOf(params.get("code"));
                    templateParam = "{\"code\":\"" + code + "\"}";//短信模板变量对应的实际值
                    break;
                default:
                    logger.info("阿里云短信发送失败,{}", "场景错误");
                    break;
            }
            String phone = String.valueOf(params.get("phone"));
            // 复制代码运行请自行打印 API 的返回值
            logger.info("发送短信,手机号：{},内容:{}:{}", phone, tem, templateParam);
            String code = SmsService.aliyunSendSms_zyyc(phone, tem, templateParam);
            logger.info("阿里云短信:" + code);
            logger.info("测试发送短信,手机号：{},内容:{}:{}", phone, tem, templateParam);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("阿里云短信发送失败,{}", e.getMessage());
        }

    }

}
